/*
 ***************************************************************************
 * MediaTeK Inc.
 * 4F, No. 2 Technology	5th	Rd.
 * Science-based Industrial	Park
 * Hsin-chu, Taiwan, R.O.C.
 *
 * (c) Copyright 2002-2012, MTK.
 *
 * All rights reserved.	MediaTeK's source	code is	an unpublished work	and	the
 * use of a	copyright notice does not imply	otherwise. This	source code
 * contains	confidential trade secret material of MediaTeK Tech. Any attemp
 * or participation	in deciphering,	decoding, reverse engineering or in	any
 * way altering	the	source code	is stricitly prohibited, unless	the	prior
 * written consent of MediaTeK, Inc. is obtained.
 ***************************************************************************

	Module Name:
	omci_me_mac_bridge.h

	Abstract:

	Revision History:
	Who			When			What
	--------	----------		----------------------------------------------
	Name		Date			Modification logs
	wayne.lee	2012/7/28	Create
*/

#ifndef _OMCI_MAC_BRIDGE_ME_H_
#define _OMCI_MAC_BRIDGE_ME_H_

#include <stdint.h>
#include "omci_adpt_common.h"

#ifdef TCSUPPORT_PON_MAC_FILTER
#include "lib_pon_mac_filter.h"
#endif


extern uint16_t validAniPortFlag[MAX_OMCI_ANI_PORT_NUM][MAX_OMCI_ANI_PORT_VALID_NUM];

#ifndef TCSUPPORT_PON_MAC_FILTER
/*******************************************************************************************************************************
MAC FILTER API  function  Start

********************************************************************************************************************************/
typedef struct pon_mac_filter_rule_s
{
         uint8_t filter_type;//0:forward 1:discard
         uint8_t mac_type;//0:des mac 1:src mac
         uint16_t ethertype;//0:don't care
         uint8_t start_mac[6];//0:don'tcare
         uint8_t end_mac[6];//0:don't care
 }pon_mac_filter_rule, * pon_mac_filter_rule_p;
/*******************************************************************************************************************************
MAC FILTER API  End 

********************************************************************************************************************************/
#endif

/*******************************************************************************************************************************
ANI port list

********************************************************************************************************************************/
#define OMCI_VALID_MAC_BRIDGE_PORT_FLAG		1
#define OMCI_INVALID_MAC_BRIDGE_PORT_FLAG	0

#define OMCI_ADD_MAC_BRIDGE_ANI_PORT		0
#define OMCI_DEL_MAC_BRIDGE_ANI_PORT		1
#define OMCI_MOD_MAC_BRIDGE_ANI_PORT		2 //modify
#define OMCI_RECFG_MAC_BRIDGE_ANI_PORT		4 //uplink to link (modify interfane match rule with gemport )

/*9.3.1*/
#define MAX_OMCI_LAN_PORT_MASK			0x0f
#define OMCI_LAN_PORT1_OTHER_MASK		0xf0
#define MAX_OMCI_LAN_PORT_DEFAULT_MASK	0xff

#define OMCI_MAC_BRIDGE_LAN_PORT1		0 
#define OMCI_MAC_BRIDGE_LAN_PORT2		1 
#define OMCI_MAC_BRIDGE_LAN_PORT3		2 
#define OMCI_MAC_BRIDGE_LAN_PORT4		3 
#define OMCI_MAC_BRIDGE_ENABLE_DISCARD	0
#define OMCI_MAC_BRIDGE_DISABLE_DISCARD	1



/*9.3.4*/
#define OMCI_IN_BOUND			1
#define OMCI_OUT_BOUND			0
#define OMCI_MBP_UNI_ISOLATE_DEFAULT_VAL	0xffffffff
#define OMCI_USER_ISOLATION_DISABLE	 	0
#define OMCI_USER_ISOLATION_ENABLE	 	1
#define OMCI_USER_ISOLATION_SET_GROUP 	2

#define OMCI_USER_ISOLATION_MAX_PORT	3
typedef struct pthreadArgUserIso_s{
	uint8_t action; 
	uint8_t portId;
	uint8_t reserved[2];
	uint32_t group;
}pthreadArgUserIso_t, *pthreadArgUserIso_p;



#define OMCI_MAC_BRIDGE_PORT_TP_TYPE_1	1 //physical path termination point ethernet uni
#define OMCI_MAC_BRIDGE_PORT_TP_TYPE_3	3 //802.1p mapper service profile
#define OMCI_MAC_BRIDGE_PORT_TP_TYPE_4	4 //IP host config data
#define OMCI_MAC_BRIDGE_PORT_TP_TYPE_5	5 //GEM interworking termination point
#define OMCI_MAC_BRIDGE_PORT_TP_TYPE_6	6 //multicast gem interworking termination point
#define OMCI_MAC_BRIDGE_PORT_TP_TYPE_11	11 //virtual ethernet interface point

#define OMCI_MAC_BRIDGE_PORT_TP_TYPE_ATTR 		1 //9.3.4 TP type attribute
#define OMCI_MAC_BRIDGE_PORT_TP_POINTE_ATTR 	2 //9.3.4 TP pointer attribute

#define OMCI_MAC_BRIDGE_PORT_CFG_DATA_ATTR_11	11	//outbound TD pointer attribute 	
#define OMCI_MAC_BRIDGE_PORT_CFG_DATA_ATTR_12	12	//inbound TD pointer attribute

#define OMCI_MAC_BRIDGE_PORT_LAN_IFC		0 //lan interface
#define OMCI_MAC_BRIDGE_PORT_WAN_IFC	1 //wan interface

#define OMCI_MAC_BRIDGE_PORT_MULTICAST_TP	1
#define OMCI_MAC_BRIDGE_PORT_GEM_TP			2
#define OMCI_MAC_BRIDGE_PORT_DOT1P			3
#define OMCI_MAC_BRIDGE_PORT_PPTP_UNI		4
#ifdef TCSUPPORT_PON_IP_HOST
#define OMCI_MAC_BRIDGE_PORT_IP_CONFIG_HOST		5
#endif
#define OMCI_MAC_BRIDGE_PORT_VEIP           6
#define MAX_GEM_PORT_NUM					256 //max gem port number(1~256)
#define MAX_MAC_BRIDGE_PORT_GEM_PORT_NUM	8 //max gem port in a mac bridge port
#define MAX_MAC_BRIDGE_PORT_UNI_PORT_NUM	8

#ifdef TCSUPPORT_PON_IP_HOST
#define IP_HOST_CONFIG_PORT_BASIC 100
#endif

/*constant define*/
/*spanning tree protocol*/
#if 1//def CZ_OLT
#define MIN_STP_MAX_AGE			6 /*6 seconds*/
#define MAX_STP_MAX_AGE			40 /*40 seconds*/
#define MIN_STP_HELLO_TIME 		1 /*1 seconds*/
#define MAX_STP_HELLO_TIME	 	10 /*10 seconds*/
#define MIN_STP_FORWARD_DELAY 	4 /*4 seconds*/
#define MAX_STP_FORWARD_DELAY 	30 /*30 seconds*/
#else
#define MIN_STP_MAX_AGE	0x0600 /*6 seconds*/
#define MAX_STP_MAX_AGE	0x2800 /*40 seconds*/
#define MIN_STP_HELLO_TIME 	0x0100 /*1 seconds*/
#define MAX_STP_HELLO_TIME	 	0x0a00 /*10 seconds*/
#define MIN_STP_FORWARD_DELAY 	0x0400 /*4 seconds*/
#define MAX_STP_FORWARD_DELAY 	0x1e00 /*30 seconds*/
#endif
#define MIN_DYNAMIC_FILTER_AGEING_TIME 	10 /*10 seconds*/
#define MAX_DYNAMIC_FILTER_AGEING_TIME 	1000000 /*1000000 seconds*/

/*performance monitoring history data*/
#define MAX_INTERVAL_END_TIME	255 /*interval end time */

/*mac bridge port information , store releation PON interface with gem port list*/
#define OMCI_VALID_MB_PORT_GEM_PORT		1
#define OMCI_INVALID_MB_PORT_GEM_PORT	0

#define OMCI_UPDATE_UNI_MAPPING_BY_VLAN_FILTER_ME	1
#define OMCI_UPDATE_UNI_MAPPING_BY_DOT1P_ME			2
#define OMCI_UPDATE_UNI_MAPPING_BY_USERPORT_ME		3

typedef struct mb_port_info_s{
	struct mb_port_info_s *next;
	uint16_t instId;//9.3.4 instance id
	uint8_t type;//0:LAN, 1:WAN
	uint8_t reserve;
	uint16_t gemlist[MAX_MAC_BRIDGE_PORT_GEM_PORT_NUM][2]; //element 0:valid/invalid , element 1:gem port id	
}mb_port_info_t, *mb_port_info_ptr;

typedef struct mb_uni_ani_port_s{
	uint16_t index;
	uint8_t ifaceType;
	uint16_t gemPortList[MAX_MAC_BRIDGE_PORT_GEM_PORT_NUM];
	uint16_t lan_portId;
	uint8_t valid;
	uint16_t gemNum;
}mb_uni_ani_port_t, *mb_uni_ani_port_ptr;

typedef struct mb_all_gemport_s{
	uint16_t gemportId;
	uint8_t valid;
}mb_all_gemport_t, *mb_all_gemport_ptr;



/*9.3.5*/
#define OMCI_MAC_BRIDGE_PORT_STATE_0		0 //disable
#define OMCI_MAC_BRIDGE_PORT_STATE_6		6 //STP_OFF

/*9.3.6 and 9.3.7*/
#define OMCI_MAC_FILTER_TYPE				0 //9.3.6
#define OMCI_PKT_FILTER_TYPE				1 //9.3.7

#define MAX_OMCI_MAC_BRIDGE_FILTER_SIMULTANEOUS_RULE_NUM	4 //max rule number in a attribute

#define OMCI_MAC_BRIDGE_FILTER_LAN_PORT_BASIC			11
#define OMCI_MAC_BRIDGE_FILTER_WAN_PORT_BASIC			51

#define  OMCI_FIND_RULE						1
#define  OMCI_NO_FIND_RULE					0

#define OMCI_MAC_BRIDGE_PORT_MAC_FILTER_TBL_TYPE_DEFAULT	2
#define OMCI_MAC_BRIDGE_PORT_MAC_FILTER_TBL_TYPE_FILTER	1 //blacklist
#define OMCI_MAC_BRIDGE_PORT_MAC_FILTER_TBL_TYPE_FORWARD	0 //white list

#define OMCI_MAC_BRIDGE_PORT_MAC_FILTER_DEL_ENTRY		0 //remove this entry
#define OMCI_MAC_BRIDGE_PORT_MAC_FILTER_CLEAR_ENTRY		1 //clear entry table
#define OMCI_MAC_BRIDGE_PORT_MAC_FILTER_ADD_ENTRY		2 //add this entry


#define OMCI_MAC_LENGTH 6

#define MAC_FILTER_RECORD_LENGTH 8
/*  	filterType: 
	Bit 	Name			Setting
	1	filter/forward		0:forward,1:filter
	2					0:dest mac, 1:src mac
	3~6	reserved
	7~8	add/remove		00:remove this entry, 01:addthis entry, 10:clear entire table
	*/	
#define MAC_FILTER_TYPE_80						0x80 // only consider add, dest bits, don't consider bit 0
#define MAC_FILTER_TYPE_80_VALID_BITS			0xc2


#define OMCI_MAC_FILTER_ETHERTYPE_ENABLED 	1
#define OMCI_MAC_FILTER_ETHERTYPE_DISABLED 	0

#define MAC_FILTER_TABLE_ENTRY		0 //9.3.6
#define MAC_FILTER_IPV4_MULTICAST		1
#define MAC_FILTER_IPV6_MULTICAST		2
#define MAC_FILTER_IPV4_BROADCAST		3
#define MAC_FILTER_RARP				4
#define MAC_FILTER_IPX					5
#define MAC_FILTER_NETBEUL				6
#define MAC_FILTER_AARP				7
#define MAC_FILTER_MANAGE_INFO		8
#define MAC_FILTER_ARP					9
#define MAC_FILTER_PPPOE_BROADCAST	10

#define OMCI_MAC_FILTER_RULE_TYPE_FORWARD			0
#define OMCI_MAC_FILTER_RULE_TYPE_DISCARD			1
#define OMCI_MAC_FILTER_RULE_MAC_TYPE_DST			0 //dest mac
#define OMCI_MAC_FILTER_RULE_MAC_TYPE_SRC			1 //src mac

#define OMCI_MAC_FILTER_RULE_ETHERTYPE_0				0 //don't care ethertype
#define OMCI_MAC_FILTER_RULE_ETHERTYPE_0800			0x0800 //ipv4 broadcast 
#define OMCI_MAC_FILTER_RULE_ETHERTYPE_8035			0x8035 //RARP
#define OMCI_MAC_FILTER_RULE_ETHERTYPE_8137			0x8137 //IPX
#define OMCI_MAC_FILTER_RULE_ETHERTYPE_809b			0x809b //appletalk
#define OMCI_MAC_FILTER_RULE_ETHERTYPE_80f3			0x80f3 //appletalk
#define OMCI_MAC_FILTER_RULE_ETHERTYPE_0806			0x0806 //ARP
#define OMCI_MAC_FILTER_RULE_ETHERTYPE_8863			0x8863 //PPPoE broadcast

 #define MAX_OMCI_MAC_FILTER_RULE_ONE_PORT			32 //max mac filter rule number in a port
 #define MAX_OMCI_MAC_FILTER_9_3_7_RULE_ONE_PORT	15 //max mac filter rule number of port in 9.3.7
 #define MAX_OMCI_MAC_FILTER_9_3_6_RULE_ONE_PORT	17 //max mac filter rule number of port in 9.3.6

/*9.3.8*/
 
#define ETH_PORT_STS    "/proc/tc3162/eth_port_status"

/*9.3.11*/
#define OMCI_PON_INTERFACE_PREFIX_STR	"nas"
#define OMCI_LAN_INTERFACE_PREFIX_STR	"eth0."

#define MAX_MAC_BRIDGE_RECORD_BUF 40
#define MAX_OMCI_IFC_NAME_LEN				16
#define  OMCI_MAC_FILTER_FLAG_0			0 //forward
#define  OMCI_MAC_FILTER_FLAG_1			1 //filter


int getMacBridgePortInstType(uint16_t instId, uint8_t * ifcType);
int getMacBridgeLanPortId(uint16_t instId, uint8_t *lanPortId);
int getMacBridgeWanPortId(uint16_t instId, uint8_t *wanPortId);
int getPortFromMacBridgeByInstId(OUT uint8_t *portId, OUT uint8_t * ifaceType, IN uint16_t instId);

int getPortFromMacBridgeSkipUNIFilterRuleByInstId(OUT uint8_t * skip_filter_flag, IN uint16_t instId);
int updateGemMappingRuleByMbPortUNI(uint8_t mapType, uint16_t instId);
int getGemPortByMACBridgePortInst(IN uint16_t instanceId, OUT uint16_t * gemPort, OUT uint8_t * validGemPortNum);
int getGemPortIdFromGemInterTP(IN uint16_t classId, IN  uint16_t instId, OUT uint16_t *gemPortId);
int setMacBridgePortDeviceId(IN uint16_t instId, IN uint8_t type);
int setMacBridgePortInfoToRomfile(IN uint16_t instanceId);
int getMacBridgePortIfcByInst(IN uint16_t instanceId, OUT char * ifcName);

int omciRecfgIfc(void);
int clearOmciMBInfo(void);

int omci_me_mac_bridge_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info);
int omci_me_mac_br_port_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info);
int omci_me_eth_frame_up_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info);
int omci_me_eth_frame_down_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info);


int get_mac_bridge_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag);
int get_mac_br_port_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag);
int get_eth_frame_up_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag);
int get_eth_frame_down_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag);

int omci_me_mac_bridge_pm_history_get_curr_op(management_entry_ptr me_entry, omci_me_info_ptr me_info);


extern omci_attr_dscp_t omci_attr_mac_br_service_op[];
extern omci_me_func_t omci_me_mac_br_service_op;
extern omci_attr_t omci_mac_br_service_attr;

extern omci_attr_dscp_t omci_attr_mac_br_pm_his_op[];
extern omci_me_func_t omci_me_mac_br_pm_his_op;
extern omci_attr_t omci_mac_br_pm_his_attr;

extern omci_attr_dscp_t omci_attr_mac_br_port_cfg_op[];
extern omci_me_func_t omci_me_mac_br_port_cfg_op;
extern omci_attr_t omci_mac_br_port_cfg_attr;

extern omci_attr_dscp_t omci_attr_mac_br_port_pm_his_op[];
extern omci_me_func_t omci_me_mac_br_port_pm_his_op;
extern omci_attr_t omci_mac_br_port_pm_his_attr;

extern omci_attr_dscp_t omci_attr_eth_frame_pm_his_up_op[];
extern omci_me_func_t omci_me_eth_frame_pm_his_up_op;
extern omci_attr_t omci_eth_frame_pm_his_up_attr;

extern omci_attr_dscp_t omci_attr_eth_frame_pm_his_down_op[];
extern omci_me_func_t omci_me_eth_frame_pm_his_down_op;
extern omci_attr_t omci_eth_frame_pm_his_down_attr;

extern omci_attr_dscp_t omci_attr_mac_br_cfg_data_op[];
extern omci_me_func_t omci_me_mac_br_cfg_data_op;
extern omci_attr_t omci_mac_br_cfg_data_attr;

extern omci_attr_dscp_t omci_attr_mac_br_port_dest_op[];
extern omci_me_func_t omci_me_mac_br_port_dest_op;
extern omci_attr_t omci_mac_br_port_dest_attr;

extern omci_attr_dscp_t omci_attr_mac_br_port_filter_op[];
extern omci_me_func_t omci_me_mac_br_port_filter_op;
extern omci_attr_t omci_mac_br_port_filter_attr;


extern omci_attr_dscp_t omci_attr_mac_br_port_filter_pre_op[];
extern omci_me_func_t omci_me_mac_br_port_filter_pre_op;
extern omci_attr_t omci_mac_br_port_filter_pre_attr;

extern omci_attr_dscp_t omci_attr_mac_br_port_br_tbl_op[];
extern omci_me_func_t omci_me_mac_br_port_br_tbl_op;
extern omci_attr_t omci_mac_br_port_br_tbl_attr;

#endif

